//
//  UIView+Add.m
//  Trank
//
//  Created by Clover on 7/15/17.
//  Copyright © 2017 Clover. All rights reserved.
//

#import "UIView+Add.h"

@implementation UIView (Add)

- (CGFloat)top {
    return self.frame.origin.y;
}

- (void)setTop:(CGFloat)top {
    CGRect rect = self.frame;
    rect.origin.y = top;
    self.frame = rect;
}

- (CGFloat)right {
    return self.frame.origin.x + self.frame.size.width;
}

- (void)setRight:(CGFloat)right {
    CGRect rect = self.frame;
    CGFloat x = right - rect.size.width;
    self.frame = CGRectMake(x, rect.origin.y, rect.size.width, rect.size.height);
}

- (CGFloat)bottom {
    return self.frame.origin.y + self.frame.size.height;
}

- (void)setBottom:(CGFloat)bottom {
    CGRect rect = self.frame;
    CGFloat y = bottom - rect.size.height;
    self.frame = CGRectMake(rect.origin.x, y, rect.size.width, rect.size.height);
}

- (CGFloat)left {
    return self.frame.origin.x;
}

- (void)setLeft:(CGFloat)left {
    CGRect rect = self.frame;
    self.frame = CGRectMake(left, rect.origin.y, rect.size.width, rect.size.height);
}

- (CGFloat)width {
    return self.frame.size.width;
}

- (void)setWidth:(CGFloat)width {
    CGRect rect = self.frame;
    self.frame = CGRectMake(rect.origin.x, rect.origin.y, width, rect.size.height);
}

- (CGFloat)height {
    return self.frame.size.height;
}

- (void)setHeight:(CGFloat)height {
    CGRect rect = self.frame;
    self.frame = CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, height);
}

- (CGFloat)centerX {
    return self.center.x;
}

- (void)setCenterX:(CGFloat)centerX {
    CGPoint point = self.center;
    point.x = centerX;
    self.center = point;
}

- (CGFloat)centerY {
    return self.center.y;
}

- (void)setCenterY:(CGFloat)centerY {
    CGPoint point = self.center;
    point.y = centerY;
    self.center = point;
}
@end
